<?php if (!defined('__FW_RUN__')) exit('not found');
/**
 * conf.initialize.php
 *
 * Dispatcher 객체 생성 이후 처리될 초기화 설정들을 지정합니다.
 *
 * @package conf
 * @author  Platform Team
 */
if (!function_exists('autoInitializeExecute')) {

    function autoInitializeExecute()
    {
        $Model = Model::getInstance();
        $Session = Session::getInstance();
        $Optimizer = Optimizer::getInstance();
        $Language = Language::getInstance();
        $View = View::getInstance();
        $Dispatcher = Dispatcher::instance();

        //Model 초기화
        $Model->initialize(Configure::get('FW.database'), Configure::get('FW.database_exec_disabled'));

        //Session 초기화
        $Session->initialize(array(
            'sess_type' => Configure::get('FW.session_type'),
            'sess_name' => Configure::get('FW.session_name'),
            'sess_domain' => Configure::get('FW.session_domain'),
            'sess_expire' => Configure::get('FW.session_expire'),
            'sess_encrypt' => Configure::get('FW.session_encrypt'),
            'sess_encrypt_handler' => Configure::get('FW.session_encrypt_handler'),
            'sess_encrypt_iv' => Configure::get('FW.session_encrypt_iv'),
            'sess_encrypt_key' => Configure::get('FW.session_encrypt_key'),
            'sess_gc_probability' => Configure::get('FW.session_gc_probability'),
            'sess_gc_maxlife' => Configure::get('FW.session_gc_maxlife'),
            'sess_memcache_host' => Configure::get('FW.session_memcache_host'),
            'sess_memcache_port' => Configure::get('FW.session_memcache_port'),
            'sess_memcache_persistent' => Configure::get('FW.session_memcache_persistent'),
            'sess_files_save_path' => Configure::get('FW.session_files_save_path'),
            'sess_name_by_cookie' => Configure::get('FW.session_name_by_cookie'),
            'sess_verify_key_id' => Configure::get('FW.session_verify_key_id'),
            'sess_verify_key_ipaddr' => Configure::get('FW.session_verify_key_ipaddr'),
            'sess_verify_key_init_access' => Configure::get('FW.session_verify_key_init_access'),
            'sess_verify_key_access' => Configure::get('FW.session_verify_key_access'),
            'sess_hash_bits_per_character' => Configure::get('FW.session_hash_bits_per_character'),
            'sess_hash_function' => Configure::get('FW.session_hash_function'),
            'sess_ip_valid_use' => Configure::get('FW.session_ip_valid_use'),
            'sess_ip_valid_exception_use' => Configure::get('FW.session_ip_valid_exception_use'),
            'sess_cookie_lifetime' => Configure::get('FW.session_cookie_lifetime'),
            'sess_cookie_path' => Configure::get('FW.session_cookie_path'),
        ));

        //Optimizer 초기화
        $Optimizer->initialize();

        //Uipack 초기화
        Uipack::initialize($Optimizer, Sslwrap::instance());

        //Language 초기화
        if (FW_LANGUAGE_ENABLE === true) {
            $Language->initialize($Optimizer, Configure::get('FW.language'), FW_LANGUAGE_JS_USE);
            $Language->import(FW_DIR_RESOURCE, r()->getControllerPath());
        }

        //View 초기화
        $View->initialize($Language);

        //Dispatcher 초기화
        $Dispatcher->initModel($Model);
        $Dispatcher->initView($View);
        $Dispatcher->initLanguage($Language);
        $Dispatcher->initOptimizer($Optimizer);
        $Dispatcher->initialize(r()->getController(), r()->getMethod(), r()->getMethodParam());

        //i18n 초기화
        if (Configure::get('FW.i18n_enabled') === true) {
            $i18n = FW_i18n::getInstance();
            $i18n->initialize(array(
                'enabled' => Configure::get('FW.i18n_enabled'),
                'locale' => Configure::get('FW.i18n_locale'),
                'locale_category' => Configure::get('FW.i18n_locale_category'),
                'directory' => Configure::get('FW.i18n_directory'),
                'domain' => Configure::get('FW.i18n_domain'),
                'bind_domain' => Configure::get('FW.i18n_bind_domain'),
                'cache_root' => Configure::get('FW.i18n_cache_root'),
                'auto_refresh' => Configure::get('FW.i18n_auto_refresh'),
                'optimizer' => $Optimizer
            ));
        }
    }

}
